home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Paypal_En / Configuration / Commands / Edit PayPal Subscriptions.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  18.2 KB  |  502 lines

  1. /*-----------------------------------------------------------------------------
  2. -    File Name:
  3. -        Edit PayPal Subscriptions.js
  4. -
  5. -    Description:
  6. -        Functions for PayPal Subscriptions Advanced Mode.
  7. -
  8. -    This file contains proprietary and confidential information from WebAssist.com
  9. -    corporation.  Any unauthorized reuse, reproduction, or modification without
  10. -    the prior written consent of WebAssist.com is strictly prohibited.
  11. -
  12. -    Copyright 2002 WebAssist.com Corporation.  All rights reserved.
  13. ------------------------------------------------------------------------------*/
  14. var CURRENTPAGE = 0;
  15. var INSPECTIONPARAMS = false;
  16. var INTERFACE        = "advanced";
  17. var theOrig = "";
  18.  
  19. function commandButtons()     {
  20.   return new Array();
  21. }
  22.  
  23. function displayHelp()     {
  24.   INTERFACE   = "advanced";
  25.   displayContextHelp();
  26. }
  27.  
  28. function receiveArguments(charttype, ssRec, paramString)     {
  29.   INSPECTIONPARAMS = true;
  30. }
  31.  
  32. /* Initialize the UI.  First thing that's called on the body load event. */
  33. function initializeUI()     {
  34.   MM.setBusyCursor();
  35.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  36.     document.background.document.tabBgWin.src = "../Shared/PayPal/images/AdvancedBG_Mac.gif";
  37.     document.Tab0.document.tabBG.src = "../Shared/PayPal/images/tabBg_Mac.gif";
  38.     document.Tab1.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  39.     document.Tab2.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  40.     document.Tab3.document.tabBG.src = "../Shared/PayPal/images/TabBg_Mac.gif";
  41.     document.background.style = "top:23px;";
  42.     
  43.     document.cancel.style = "position:absolute; width:70px; height:20px; z-index:94; left: 310px; top: 373px; visibility: visible";
  44.     document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  45.     
  46.     document.OK.style = "position:absolute; width:70px; height:20px; z-index:94; left: 380px; top: 373px; visibility: visible";
  47.     document.OK.document.btnOK.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  48.     
  49.     document.help.style = "position:absolute; width:70px; height:20px; z-index:94; left: 240px; top: 373px; visibility: visible";
  50.     document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  51.   
  52.     document.walogo.top = 375;
  53.     document.pplogo.top = 376;
  54.     }
  55.   document.OK.visibility = "visible";
  56.   document.cancel.visibility = "visible";
  57.   document.help.visibility = "visible";
  58.   document.background.visibility = "visible";
  59.   document.Tab0.visibility = "visible";
  60.   document.Tab1.visibility = "visible";
  61.   document.Tab2.visibility = "visible";
  62.   document.Tab3.visibility = "visible";
  63.   // Get values from the inspected node and populate our UI accordingly
  64.   var theDOM = dw.getDocumentDOM();
  65.   var theSelection = theDOM.getSelectedNode();
  66.   theOrig = unescape(theSelection.orig);
  67.  
  68.   while (theSelection.tagName!="FORM" && theSelection.parentNode && theSelection.PPwholeForm!="true")  {
  69.     theSelection = theSelection.parentNode;
  70.   }
  71.   theOrig = theSelection.outerHTML;
  72.  
  73.   var tempOrig = theOrig;
  74.   var firstInput = findOpenTag(tempOrig,"input");
  75.   while (firstInput != "")
  76.   {
  77.     var inputName = getTagProp(firstInput,"input","name");
  78.     var theVal = getTagProp(firstInput,"input","value");
  79.     switch (inputName.toLowerCase())
  80.     {
  81.       case "business":
  82.         if (theVal != "")   
  83.           document.generalWP.document.ppUID.value = theVal;      
  84.         break;
  85.  
  86.       case "item_name":
  87.         if (theVal != "")   
  88.           document.itemWP.document.subscriptionName.value = theVal;      
  89.         break;
  90.  
  91.       case "item_number":
  92.         if (theVal != "")   
  93.           document.itemWP.document.subscriptionID.value = theVal;      
  94.         break;
  95.  
  96.       case "currency_code":
  97.         var theCurrency = document.itemWP.document.itemCurrency;      
  98.         for (var n=0; n<theCurrency.options.length; n++)
  99.         {
  100.             if (theVal == theCurrency.options[n].value)
  101.             {
  102.               theCurrency.selectedIndex = n;
  103.               break;
  104.             }
  105.         }              
  106.         break;                                                                                
  107.                 
  108.       case "a1":
  109.         if (theVal != "")   
  110.           document.itemWP.document.trial1Amount.value = theVal;            
  111.         break;
  112.  
  113.       case "p1": 
  114.         var trialValue = document.itemWP.document.trial1Value;
  115.         for (var i=0; i<trialValue.options.length; i++)
  116.         {
  117.           if (trialValue.options[i].value == theVal)
  118.           {
  119.             trialValue.selectedIndex = i;
  120.           }      
  121.         }    
  122.         break;
  123.               
  124.       case "t1": 
  125.         var trialValue = document.itemWP.document.trial1Period;
  126.         for (var i=0; i<trialValue.options.length; i++)
  127.         {
  128.           if (trialValue.options[i].value == theVal)
  129.           {
  130.             trialValue.selectedIndex = i;
  131.           }      
  132.         }    
  133.         break;
  134.               
  135.  
  136.       case "a3":
  137.         if (theVal != "")   
  138.           document.itemWP.document.subscriptionPrice.value = theVal;            
  139.         break;
  140.  
  141.       case "p3": 
  142.         var trialValue = document.itemWP.document.billingValue;
  143.         for (var i=0; i<trialValue.options.length; i++)
  144.         {
  145.           if (trialValue.options[i].value == theVal)
  146.           {
  147.             trialValue.selectedIndex = i;
  148.           }      
  149.         }    
  150.         break;
  151.               
  152.       case "t3": 
  153.         var trialValue = document.itemWP.document.billingPeriod;
  154.         for (var i=0; i<trialValue.options.length; i++)
  155.         {
  156.           if (trialValue.options[i].value == theVal)
  157.           {
  158.             trialValue.selectedIndex = i;
  159.           }      
  160.         }    
  161.         break;
  162.                                                
  163.       case "image_url":
  164.         if (isValidURL(theVal))   
  165.           document.generalWP.document.ppLogo.value = theVal;            
  166.         break;
  167.  
  168.       case "return":
  169.         if (isValidURL(theVal))   
  170.           document.generalWP.document.successURL.value = theVal;
  171.         break;
  172.         
  173.       case "cancel_return":
  174.         if (isValidURL(theVal))   
  175.           document.generalWP.document.cancelURL.value = theVal;      
  176.         break;
  177.   
  178.       case "src":
  179.         if (theVal == "1")
  180.         {
  181.           document.itemWP.document.recurringBilling[0].checked = true;
  182.         }
  183.         else
  184.         {
  185.           document.itemWP.document.recurringBilling[1].checked = true;        
  186.         }
  187.         break;                                                                                
  188.  
  189.       case "srt":
  190.         document.itemWP.document.recurringBilling[1].checked = true;        
  191.         var srtValue = document.itemWP.document.stopRecurringValue;
  192.         for (var i=0; i<srtValue.options.length; i++)
  193.         {
  194.           if (srtValue.options[i].value == theVal)
  195.           {
  196.             srtValue.selectedIndex = i;
  197.           }      
  198.         }            
  199.         break;                                                                                
  200.                   
  201.       case "sra":
  202.         if (theVal == "1")
  203.         {
  204.           document.optionWP.document.reattemptBilling[0].checked = true;
  205.         }
  206.         else
  207.         {
  208.           document.optionWP.document.reattemptBilling[1].checked = true;        
  209.         }
  210.         break;                                                                                
  211.                           
  212.       case "no_shipping":
  213.         if (theVal == "0")
  214.         {
  215.           document.optionWP.document.includeShipping[0].checked = true;
  216.         }
  217.         else
  218.         {
  219.           document.optionWP.document.includeShipping[1].checked = true;        
  220.         }
  221.         break;                                                                                
  222.  
  223.       case "submit":  // button image URL
  224.         var theImg = document.buttonWP.document.subimage;   
  225.         theVal = getTagProp(firstInput,"input","src");
  226.         var myImage = getTranslatedSUBImage(theVal);
  227.         if (myImage == CUSTOM_SUB_IMG)
  228.         {
  229.           myImage = "other";
  230.           document.buttonWP.document.othersubimage.value = theVal;
  231.         }
  232.         
  233.         for (var n=0; n<theImg.length; n++)
  234.         {
  235.             if (myImage == theImg[n].value)
  236.             {
  237.               theImg[n].checked = true;
  238.             }
  239.             else
  240.             {
  241.               theImg[n].checked = false;
  242.             }
  243.         }              
  244.         break;                                                                                
  245.                         
  246.       default:
  247.         break;
  248.     }   
  249.  
  250.     tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length); 
  251.     firstInput = findOpenTag(tempOrig,"input");
  252.     
  253.   }  
  254.  
  255.   enableDisableOtherImage();
  256.   enableDisableStopRecurring();
  257.   
  258.   // Go to the item details page
  259.   showPageNum(2);
  260.   
  261.   MM.clearBusyCursor();
  262.   
  263.   return true;
  264. }
  265.  
  266. /******************************** support functions ******************/
  267. function generateSUB()
  268. {
  269.   var myErrors = validateUI();
  270.   if (myErrors == "")
  271.   {
  272.     updateSUB(theOrig);
  273.   }
  274.   else
  275.   {
  276.     alert (myErrors);
  277.   }
  278.  
  279.   return;
  280. }
  281.  
  282. function validateUI()    {
  283.   var errMsg = "";
  284.   errMsg += validatePPUID();
  285.   if (errMsg != "")     {
  286.     errMsg = "Account " + errMsg;
  287.   }
  288.   errMsg += validateSubsDetails();     
  289.   if ( errMsg != "" )
  290.   {
  291.     errMsg = "The following errors were found:\n\n" + errMsg;
  292.   }
  293.  
  294.   return errMsg;
  295. }
  296.  
  297. function enableDisableOtherImage()     {
  298.   var myImage = document.buttonWP.document.subimage;
  299.   for (var n=0; n<myImage.length; n++)
  300.   {
  301.     if (myImage[n].checked)
  302.     {
  303.       if (myImage[n].value == "other")
  304.       {
  305.         document.buttonWP.document.othersubimage.disabled = "enabled";
  306.       }
  307.       else
  308.       {
  309.         document.buttonWP.document.othersubimage.disabled = "disabled";
  310.       }
  311.     }
  312.   }
  313. }
  314.  
  315. function enableDisableStopRecurring()   {
  316.   if (document.itemWP.document.recurringBilling[1].checked)
  317.   {
  318.     document.itemWP.document.stopRecurringValue.disabled = "enabled";
  319.   }
  320.   else
  321.   {
  322.     document.itemWP.document.stopRecurringValue.disabled = "disabled";    
  323.   } 
  324. }
  325.  
  326. function updateSUB(formTag)  {
  327.   var theForm = formTag;
  328.   var theBusiness = document.generalWP.document.ppUID.value;
  329.   var theItemName = document.itemWP.document.subscriptionName.value;
  330.   var theItemNumber = document.itemWP.document.subscriptionID.value;
  331.  
  332.   var theTrialAmount = document.itemWP.document.trial1Amount.value
  333.   var theTrialPeriod = document.itemWP.document.trial1Value.options[document.itemWP.document.trial1Value.selectedIndex].value
  334.   var theTrialTime = document.itemWP.document.trial1Period.options[document.itemWP.document.trial1Period.selectedIndex].value
  335.   var theSubAmount = document.itemWP.document.subscriptionPrice.value;
  336.   var theSubPeriod = document.itemWP.document.billingValue.options[document.itemWP.document.billingValue.selectedIndex].value
  337.   var theSubTime = document.itemWP.document.billingPeriod.options[document.itemWP.document.billingPeriod.selectedIndex].value
  338.   var Recurr = (document.itemWP.document.recurringBilling[0].checked)?"1":"0";
  339.   var StopAfter = document.itemWP.document.stopRecurringValue.options[document.itemWP.document.stopRecurringValue.selectedIndex].value;
  340.   var ReAttempt = (document.optionWP.document.reattemptBilling[0].checked)?"1":"0";
  341.   var theCurrencyCode = document.itemWP.document.itemCurrency.options[document.itemWP.document.itemCurrency.selectedIndex].value;
  342.   var theImageURL = document.generalWP.document.ppLogo.value;
  343.   var theReturn = document.generalWP.document.successURL.value;
  344.   var theCancel = document.generalWP.document.cancelURL.value
  345.   var theNoShip = (document.optionWP.document.includeShipping[0].checked)?"0":"1";
  346.   var theButtonImage = document.buttonWP.document.subimage[0].value;
  347.   for (x in document.buttonWP.document.subimage)  {
  348.     if (document.buttonWP.document.subimage[x].checked)
  349.       theButtonImage = document.buttonWP.document.subimage[x].value;
  350.   }
  351.   if (theButtonImage == "other")
  352.     theButtonImage = document.buttonWP.document.othersubimage.value;
  353.   else  
  354.     theButtonImage = "http://images.paypal.com/images/" + theButtonImage;
  355.     
  356.   if (theImageURL == "https://"  || theImageURL == "http://")
  357.     theImageURL = "";
  358.   if (theReturn == "https://"  || theReturn == "http://")
  359.     theReturn = "";
  360.   if (theCancel == "https://"  || theCancel == "http://")
  361.     theCancel = "";
  362.   
  363.   if (theTrialAmount == "")  {
  364.     theTrialPeriod = "";
  365.     theTrialTime = "";
  366.   }
  367.   
  368.   if (theSubAmount == "")  {
  369.     theSubPeriod = "";
  370.     theSubTime = "";
  371.   }
  372.   
  373.   if (Recurr == "1")  {
  374.     StopAfter = "";
  375.   }
  376.     
  377.   theForm = updateFormInput(theForm,"business",theBusiness);
  378.   theForm = updateFormInput(theForm,"item_name",theItemName);
  379.   theForm = updateFormInput(theForm,"item_number",theItemNumber);
  380.   theForm = updateFormInput(theForm,"a1",theTrialAmount);
  381.   theForm = updateFormInput(theForm,"p1",theTrialPeriod);
  382.   theForm = updateFormInput(theForm,"t1",theTrialTime);
  383.   theForm = updateFormInput(theForm,"a3",theSubAmount);
  384.   theForm = updateFormInput(theForm,"p3",theSubPeriod);
  385.   theForm = updateFormInput(theForm,"t3",theSubTime);
  386.   theForm = updateFormInput(theForm,"sra",ReAttempt);
  387.   theForm = updateFormInput(theForm,"srt",StopAfter);
  388.   theForm = updateFormInput(theForm,"src",Recurr);
  389.   theForm = updateFormInput(theForm,"currency_code",theCurrencyCode);
  390.   theForm = updateFormInput(theForm,"image_url",theImageURL);
  391.   theForm = updateFormInput(theForm,"return",theReturn);
  392.   theForm = updateFormInput(theForm,"cancel_return",theCancel);
  393.   theForm = updateFormInput(theForm,"no_shipping",theNoShip);
  394.   theForm = updateFormInput(theForm,"bn",BNVersion);
  395.   theForm = updateImage(theForm,theButtonImage);
  396.   var theDOM = dreamweaver.getDocumentDOM();
  397.   var thePage = theDOM.documentElement.outerHTML;
  398.   var theSelection = theDOM.getSelectedNode();
  399.   var theOffsets = new Array();
  400.   while (theSelection.tagName!="FORM" && theSelection.PPwholeForm!="true")  {
  401.     theSelection = theSelection.parentNode;
  402.   }
  403.   theDOM.setSelectedNode(theSelection);
  404.   theDOM.insertHTML(theForm);
  405.   closeWindow();
  406. }
  407.  
  408. function updateImage(formHTML,image)  {
  409.   var theInput = /<input\s[^<]*type=(['"])image\1/i;
  410.   if (formHTML.search(theInput)>=0)  {
  411.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  412.     formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","src",image) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  413.   }
  414.   else  {
  415.     formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="image" name="submit" src="'+image+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  416.   }
  417.   return formHTML;
  418. }
  419.  
  420. function updateFormInput(formHTML,fieldName,fieldValue)  {
  421.   var theInput = new RegExp('<input\\s[^<]*name=([\'"]?)'+fieldName+'\\1',"i");
  422.   if (formHTML.search(theInput)>=0)  {
  423.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  424.     if (fieldValue!="")
  425.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","value",fieldValue) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  426.     else
  427.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  428.   }
  429.   else  {
  430.     if (fieldValue!="")
  431.       formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="hidden" name="'+fieldName+'" value="'+fieldValue+'">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  432.   }
  433.   return formHTML;
  434. }
  435.  
  436. /******************************** PAGE FUNCTIONS ********************************/
  437. function Pg0_Load()     {
  438.   document.generalWP.visibility = "visible";
  439.   setTimeout("document.generalWP.document.ppUID.focus()",500);
  440.   return true;
  441. }
  442. function Pg0_unLoad()     {
  443.   document.generalWP.visibility = "hidden";
  444.   document.generalWP.visibility = "visible";
  445.   document.generalWP.visibility = "hidden";
  446.   return true;
  447. }
  448.  
  449. function Pg1_Load()     {
  450.   document.buttonWP.visibility = "visible";
  451.   return true;
  452. }
  453. function Pg1_unLoad()     {
  454.   document.buttonWP.visibility = "hidden";
  455.   document.buttonWP.visibility = "visible";
  456.   document.buttonWP.visibility = "hidden";
  457.   return true;
  458. }
  459.  
  460. function Pg2_Load()     {
  461.   document.itemWP.visibility = "visible";
  462.   setTimeout("document.itemWP.document.subscriptionName.focus()",500);
  463.   return true;
  464. }
  465. function Pg2_unLoad()     {
  466.   document.itemWP.visibility = "hidden";
  467.   document.itemWP.visibility = "visible";
  468.   document.itemWP.visibility = "hidden";
  469.   return true;
  470. }
  471.  
  472. function Pg3_unLoad()     {
  473.   document.optionWP.visibility = "hidden";
  474.   document.optionWP.visibility = "visible";
  475.   document.optionWP.visibility = "hidden";
  476.   return true;
  477. }
  478.  
  479. function Pg3_Load()     {
  480.   document.optionWP.visibility = "visible";
  481.   //setTimeout("document.optionWP.document.reattemptBilling[0].focus()",500);
  482.   return true;
  483. }
  484.  
  485. function showPageNum(pageNum)  {
  486.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  487.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  488.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
  489.   }
  490.   else  {
  491.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
  492.   }
  493.   CURRENTPAGE = pageNum;
  494.    if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  495.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
  496.    }
  497.   else  {  
  498.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
  499.   }
  500.   eval("Pg"+CURRENTPAGE+"_Load()");
  501. }
  502.